package com.inkyi.assistant.app.component.rsyntax.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * 默认超链接侦听器
 *
 * @author lihongkun
 * @date 2025/07/29
 */
public class DefaultHyperlinkListener implements HyperlinkListener {

    public static final Logger log = LoggerFactory.getLogger(DefaultHyperlinkListener.class);

    @Override
    public void hyperlinkUpdate(HyperlinkEvent event) {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(new URI(event.getURL().toString()));
            } catch (IOException | URISyntaxException ex) {
                log.error(ex.getMessage(), ex);
            }
        }
    }
}
